home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 151-175 / disk_166 / stevie / source / param.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  161 lines

  1. /*
  2.  * STEVIE - Simply Try this Editor for VI Enthusiasts
  3.  *
  4.  * Code Contributions By : Tim Thompson           twitch!tjt
  5.  *                         Tony Andrews           onecom!wldrdg!tony 
  6.  *                         G. R. (Fred) Walter    watmath!watcgl!grwalter 
  7.  */
  8.  
  9. /*
  10.  * Code to handle user-settable parameters. This is all pretty much table-
  11.  * driven. To add a new parameter, put it in the params array, and add a
  12.  * macro for it in param.h. If it's a numeric parameter, add any necessary
  13.  * bounds checks to doset(). String parameters aren't currently supported. 
  14.  */
  15.  
  16. #include "stevie.h"
  17.  
  18. struct param    params[] = {
  19.  
  20.                 {"tabstop", "ts", 8, P_NUM},
  21.                 {"scroll", "scroll", 12, P_NUM},
  22.                 {"report", "report", 5, P_NUM},
  23.                 {"lines", "lines", 25, P_NUM},
  24.  
  25.                 {"vbell", "vb", TRUE, P_BOOL},
  26.                 {"showmatch", "sm", FALSE, P_BOOL},
  27.                 {"wrapscan", "ws", TRUE, P_BOOL},
  28.                 {"errorbells", "eb", FALSE, P_BOOL},
  29.                 {"showmode", "mo", FALSE, P_BOOL},
  30.                 {"backup", "bk", FALSE, P_BOOL},
  31.                 {"return", "cr", TRUE, P_BOOL},
  32.                 {"list", "list", FALSE, P_BOOL},
  33.                 {"autoindent", "ai", FALSE, P_BOOL},
  34.  
  35.                 {"", "", 0, 0,}    /* end marker */
  36. };
  37.  
  38. static void     showparms();
  39.  
  40. void
  41. doset(arg, inter)
  42.     char           *arg;    /* parameter string */
  43.     bool_t          inter;    /* TRUE if called interactively */
  44. {
  45.     int             i;
  46.     char           *s;
  47.     bool_t          did_lines = FALSE;
  48.  
  49.     bool_t          state = TRUE;    /* new state of boolean parms. */
  50.  
  51.     if (arg == NULL) {
  52.     showparms(FALSE);
  53.     return;
  54.     }
  55.     if (strncmp(arg, "all", 3) == 0) {
  56.     showparms(TRUE);
  57.     return;
  58.     }
  59.     if (strncmp(arg, "no", 2) == 0) {
  60.     state = FALSE;
  61.     arg += 2;
  62.     }
  63.     for (i = 0; params[i].fullname[0] != NUL; i++) {
  64.     s = params[i].fullname;
  65.     if (strncmp(arg, s, strlen(s)) == 0)    /* matched full name */
  66.         break;
  67.     s = params[i].shortname;
  68.     if (strncmp(arg, s, strlen(s)) == 0)    /* matched short name */
  69.         break;
  70.     }
  71.  
  72.     if (params[i].fullname[0] != NUL) {    /* found a match */
  73.     if (params[i].flags & P_NUM) {
  74.         did_lines = (i == P_LI);
  75.         if (inter && (arg[strlen(s)] != '=' || state == FALSE))
  76.         emsg("Invalid set of numeric parameter");
  77.         else {
  78.         params[i].value = atoi(arg + strlen(s) + 1);
  79.         params[i].flags |= P_CHANGED;
  80.         }
  81.     } else {        /* boolean */
  82.         if (inter && (arg[strlen(s)] == '='))
  83.         emsg("Invalid set of boolean parameter");
  84.         else {
  85.         params[i].value = state;
  86.         params[i].flags |= P_CHANGED;
  87.         }
  88.     }
  89.     } else {
  90.     if (inter)
  91.         emsg("Unrecognized 'set' option");
  92.     }
  93.  
  94.     /*
  95.      * Update the screen in case we changed something like "tabstop" or
  96.      * "list" that will change its appearance. 
  97.      */
  98.     if (inter)
  99.     updateNextscreen();
  100.  
  101.     if (did_lines) {
  102.     Rows = P(P_LI);
  103.     screenalloc();        /* allocate new screen buffers */
  104.     screenclear();
  105.     updateNextscreen();
  106.     }
  107.     /*
  108.      * Check the bounds for numeric parameters here 
  109.      */
  110.     if (P(P_TS) <= 0 || P(P_TS) > 32) {
  111.     if (inter)
  112.         emsg("Invalid tab size specified");
  113.     P(P_TS) = 8;
  114.     return;
  115.     }
  116.     if (P(P_SS) <= 0 || P(P_SS) > Rows) {
  117.     if (inter)
  118.         emsg("Invalid scroll size specified");
  119.     P(P_SS) = 12;
  120.     return;
  121.     }
  122.     /*
  123.      * Check for another argument, and call doset() recursively, if found. If
  124.      * any argument results in an error, no further parameters are processed. 
  125.      */
  126.     while (*arg != ' ' && *arg != '\t') {    /* skip to next white space */
  127.     if (*arg == NUL)
  128.         return;        /* end of parameter list */
  129.     arg++;
  130.     }
  131.     while (*arg == ' ' || *arg == '\t')    /* skip to next non-white */
  132.     arg++;
  133.  
  134.     if (*arg)
  135.     doset(arg, TRUE);    /* recurse on next parameter, if present */
  136. }
  137.  
  138. static void
  139. showparms(all)
  140.     bool_t          all;    /* show ALL parameters */
  141. {
  142.     struct param   *p;
  143.     char            buf[64];
  144.  
  145.     gotocmdline(YES, NUL);
  146.     outstr("Parameters:\r\n");
  147.  
  148.     for (p = ¶ms[0]; p->fullname[0] != NUL; p++) {
  149.     if (!all && ((p->flags & P_CHANGED) == 0))
  150.         continue;
  151.     if (p->flags & P_BOOL)
  152.         sprintf(buf, "\t%s%s\r\n",
  153.             (p->value ? "" : "no"), p->fullname);
  154.     else
  155.         sprintf(buf, "\t%s=%d\r\n", p->fullname, p->value);
  156.  
  157.     outstr(buf);
  158.     }
  159.     wait_return();
  160. }
  161.